package com.example.demo.controller;

import com.example.demo.mapper.FriendMapper;
import com.example.demo.model.Friend;
import com.example.demo.model.User;
import com.example.demo.service.FriendService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class FriendController {

    @Autowired
    private static Logger log = LoggerFactory.getLogger(FriendController.class);


//    @Autowired
//    private FriendMapper friendMapper;
//
//    @RequestMapping("/friendList")
//    public Object getFriendList(HttpServletRequest request)
//    {
//        //1.从会话中获取到userId
//        HttpSession session = request.getSession(false);
//        if(session == null)
//        {
//            //当前用户会话不存在,用户未登录
//            log.warn("用户未登录,会话不存在");
//            return new ArrayList<Friend>();
//        }
//        User user = (User) session.getAttribute("user");
//        List<Friend> friendList = friendMapper.selectFriendList(user.getUserId());
//        return friendList;
//    }

    @Autowired
    private FriendService friendService;

    @RequestMapping("/friendList")
    public Object getFriendList(HttpServletRequest request)
    {
        return friendService.getFriendList(request);
    }
}
